package com.unknown

import grails.plugins.springsecurity.Secured

import com.unknown.world.Tile;

@Secured(['ROLE_USER', 'ROLE_ADMIN'])
class UiController {
	def tileService
	def springSecurityService
	
	def main = {
		def user = User.findById(springSecurityService.principal.id)
		AuthenticationBroker.activeKeys.put(user.username, session.id)
				
		[username : user.username, sessionId : session.id]
	}
	def empty = {}
	def room = {}
	def imageManager = {
		def offset = params.offset ? params.getInt('offset') : 0
		def max = params.max ? params.getInt('max') : 10
		def columns = params.columns ? params.getInt('columns') : 5;
		def type = params.type ?: 'background';
		
		List<Tile> tiles = tileService.findByType(type, offset, max);

		[images:tiles, columns:columns]
	}
	
}
